package com.dataimport.service.impl;

import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dataimport.entity.sourceentity.ECardAccountInfo;
import com.dataimport.entity.sourceentity.LibraryPassThroughRecord;
import com.dataimport.entity.targetentity.ECardInfo;

import com.dataimport.mapper.ECardInfoMapper;
import com.dataimport.service.ECardInfoService;
import org.apache.ibatis.javassist.expr.NewArray;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@Service
public class ECardInfoServiceImpl extends ServiceImpl<ECardInfoMapper, ECardAccountInfo>  implements ECardInfoService {
    @Autowired
    private ECardInfoMapper eCardInfoMapper;

    @Override
    public void dealWithECardInfo() {
        DynamicDataSourceContextHolder.push("mysql2");
        List<ECardAccountInfo> eCardAccountInfos = eCardInfoMapper.selectList(null);
        List<ECardInfo> eCardInfos = new ArrayList<>();
        if(CollectionUtils.isNotEmpty(eCardAccountInfos)){
                eCardInfos = eCardAccountInfos.stream().map(eCardAccountInfo-> {
                ECardInfo eCardInfo=new ECardInfo();
                eCardInfo.setECardId(eCardAccountInfo.getYktkh());
                eCardInfo.setUserCode(eCardAccountInfo.getYktkh());
                eCardInfo.setECardAccountStatus(Long.parseLong(eCardAccountInfo.getZhztm()));
                return eCardInfo;
            }).collect(Collectors.toList());
//            eCardInfos.forEach(System.out::println);
        }

        DynamicDataSourceContextHolder.poll();

        DynamicDataSourceContextHolder.push("mysql1");
        //在这里插入
        //saveBatch(eCardInfos);

        DynamicDataSourceContextHolder.poll();
    }

}
